# Generated from live-image-text.pro.

cmake_minimum_required(VERSION 3.16)
project(live-image-text VERSION 1.0 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#live
option(WITH_MKL        "Compile demo with MKL/OpenBlas support, default use MKL."       ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    OFF)
option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static."   ON)
option(WITH_TENSORRT "Compile demo with TensorRT."   OFF)
option(WITH_RISCV "Compile on RISC-V" OFF)

SET(PADDLE_LIB "" CACHE PATH "Location of libraries")
SET(OPENCV_DIR "" CACHE PATH "Location of libraries")
SET(CUDA_LIB "" CACHE PATH "Location of libraries")
SET(CUDNN_LIB "" CACHE PATH "Location of libraries")
SET(TENSORRT_DIR "" CACHE PATH "Compile demo with TensorRT")

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
    # 如果是x86架构
    message(STATUS "Configuring for x86_64")
    # 设置x86架构特有的编译标志或者定义
    set(DEFINITIONS "-DX86")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${YOUR_DEFINITIONS}")
    set(OPENCV_DIR "${CMAKE_SOURCE_DIR}/live/x86/opencv4.9")
    set(PADDLE_LIB "${CMAKE_SOURCE_DIR}/live/x86/paddle_inference_install_dir")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv" OR CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
    # 如果是RISC-V架构
    message(STATUS "Configuring or RISC-V")
    # 设置RISC-V架构特有的编译标志或者定义
    set(DEFINITIONS "-DRISCV")
    set(WITH_MKL OFF)
    set(WITH_RISCV ON)
    ADD_DEFINITIONS(-DWITH_RISCV)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${YOUR_DEFINITIONS}")
    set(OPENCV_DIR "${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9")
    set(PADDLE_LIB "${CMAKE_SOURCE_DIR}/live/riscv/paddle_inference_install_dir")
else()
    # 其他架构
    message(STATUS "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()



macro(safe_set_static_flag)
    foreach(flag_var
            CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
            CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
        if(${flag_var} MATCHES "/MD")
            string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
        endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if(NOT DEFINED PADDLE_LIB)
    message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
endif()

find_package(OpenEXR REQUIRED)
find_package(OpenCV 4.9 REQUIRED PATHS ${OPENCV_DIR})
find_package(PkgConfig REQUIRED)
#if(NOT DEFINED OPENCV_DIR)
#    message(FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv")
#endif()


if (WIN32)
    include_directories("${PADDLE_LIB}/paddle/include")
    link_directories("${PADDLE_LIB}/paddle/lib")
    #  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)

else ()
    #  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/share/OpenCV NO_DEFAULT_PATH)
    include_directories("${PADDLE_LIB}/paddle/include")
    link_directories("${PADDLE_LIB}/paddle/lib")
endif ()
include_directories(${OpenCV_INCLUDE_DIRS})

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    if(WITH_MKL)
        set(FLAG_OPENMP "/openmp")
    endif()
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    if (WITH_STATIC_LIB)
        safe_set_static_flag()
        add_definitions(-DSTATIC_LIB)
    endif()
    message("cmake c debug flags " ${CMAKE_C_FLAGS_DEBUG})
    message("cmake c release flags " ${CMAKE_C_FLAGS_RELEASE})
    message("cmake cxx debug flags " ${CMAKE_CXX_FLAGS_DEBUG})
    message("cmake cxx release flags " ${CMAKE_CXX_FLAGS_RELEASE})
else()
    if(WITH_MKL)
        set(FLAG_OPENMP "-fopenmp")
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 ${FLAG_OPENMP} -std=c++11")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
    message("cmake cxx flags" ${CMAKE_CXX_FLAGS})
endif()

if (WITH_GPU)
    if (NOT DEFINED CUDA_LIB OR ${CUDA_LIB} STREQUAL "")
        message(FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64")
    endif()
    if (NOT WIN32)
        if (NOT DEFINED CUDNN_LIB)
            message(FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64")
        endif()
    endif(NOT WIN32)
endif()

include_directories("${PADDLE_LIB}/third_party/install/protobuf/include")
include_directories("${PADDLE_LIB}/third_party/install/glog/include")
include_directories("${PADDLE_LIB}/third_party/install/gflags/include")
include_directories("${PADDLE_LIB}/third_party/install/xxhash/include")
include_directories("${PADDLE_LIB}/third_party/install/zlib/include")
include_directories("${PADDLE_LIB}/third_party/install/onnxruntime/include")
include_directories("${PADDLE_LIB}/third_party/install/paddle2onnx/include")
include_directories("${PADDLE_LIB}/third_party/boost")
include_directories("${PADDLE_LIB}/third_party/eigen3")

include_directories("${CMAKE_SOURCE_DIR}/live")

if (NOT WIN32)
    if (WITH_TENSORRT AND WITH_GPU)
        include_directories("${TENSORRT_DIR}/include")
        link_directories("${TENSORRT_DIR}/lib")
    endif()
endif(NOT WIN32)

link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")

link_directories("${PADDLE_LIB}/third_party/install/protobuf/lib")
link_directories("${PADDLE_LIB}/third_party/install/glog/lib")
link_directories("${PADDLE_LIB}/third_party/install/gflags/lib")
link_directories("${PADDLE_LIB}/third_party/install/xxhash/lib")
link_directories("${PADDLE_LIB}/third_party/install/onnxruntime/lib")
link_directories("${PADDLE_LIB}/third_party/install/paddle2onnx/lib")
link_directories("${PADDLE_LIB}/paddle/lib")


#添加
link_directories("${PADDLE_LIB}/third_party/install/cryptopp/lib")



if(WITH_MKL)
    include_directories("${PADDLE_LIB}/third_party/install/mklml/include")
    if (WIN32)
        set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.lib
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.lib)
    else ()
        set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
        execute_process(COMMAND cp -r ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib)
    endif ()
    set(MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn")
    if(EXISTS ${MKLDNN_PATH})
        include_directories("${MKLDNN_PATH}/include")
        if (WIN32)
            set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
        else ()
            #set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
            set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libdnnl.so.3)
        endif ()
    endif()
else()
    if (WIN32)
        set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX})
    else ()
        set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
    endif ()
endif()

# Note: libpaddle_inference_api.so/a must put before libpaddle_inference.so/a
if(WITH_STATIC_LIB)
    if(WIN32)
        set(DEPS
            ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
    else()
        set(DEPS
            ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
    endif()
else()
    if(WIN32)
        set(DEPS
            ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
    else()
        set(DEPS
            ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
endif(WITH_STATIC_LIB)

if (NOT WIN32)
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags protobuf z xxhash
        )
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
else()
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags_static libprotobuf xxhash)
    set(DEPS ${DEPS} libcmt shlwapi)
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
endif(NOT WIN32)


if(WITH_GPU)
    if(NOT WIN32)
        if (WITH_TENSORRT)
            set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX})
            set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
        endif()
        set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
        set(DEPS ${DEPS} ${CUDNN_LIB}/libcudnn${CMAKE_SHARED_LIBRARY_SUFFIX})
    else()
        set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
        set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
        set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX})
    endif()
endif()


if (NOT WIN32)
    set(EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread")
    set(DEPS ${DEPS} ${EXTERNAL_LIB} -lcryptopp)
endif()

#set(DEPS ${DEPS} ${OpenCV_LIBS})

#include(FetchContent)
#include(external-cmake/auto-log.cmake)
#include_directories(${FETCHCONTENT_BASE_DIR}/extern_autolog-src)


message("opencv include: " ${OpenCV_INCLUDE_DIRS})
message("opencv lib: " ${OpenCV_LIBS})
set(live_files
    live/ner/bertinfer.h
    live/ner/bertinfer.cpp
    live/yolov8infer/yolov8infer.h
    live/yolov8infer/yolov8infer.cpp
    live/ppocr/utility.cpp
    live/ppocr/structure_table.cpp
    live/ppocr/structure_layout.cpp
    live/ppocr/preprocess_op.cpp
    live/ppocr/postprocess_op.cpp
    live/ppocr/paddlestructure.cpp
    live/ppocr/paddleocr.cpp
    live/ppocr/ocr_rec.cpp
    live/ppocr/ocr_det.cpp
    live/ppocr/ocr_cls.cpp
    live/ppocr/ocr.cpp
    live/ppocr/ocr_pub.h
    live/ppocr/clipper.cpp
    live/ppocr/args.cpp
#    live/ui/main.cpp
    live/ui/imagewindow.cpp
    live/ui/imagewindow.h
    live/ui/imageview.h
    live/ui/imageview.cpp
    live/ui/processing.h
    live/ui/processing.cpp
    live/ui/ocrthread.h
    live/ui/ocrthread.cpp
    live/ui/nerthread.h
    live/ui/nerthread.cpp
    live/ui/pubdef.h
    live/ui/pubdef.cpp
    live/include/utility.h
    live/include/structure_table.h
    live/include/structure_layout.h
    live/include/preprocess_op.h
    live/include/postprocess_op.h
    live/include/paddlestructure.h
    live/include/paddleocr.h
    live/include/ocr_rec.h
    live/include/ocr_det.h
    live/include/ocr_cls.h
    live/include/clipper.h
    live/include/args.h
    )

##end live


##live-image-text
if(NOT DEFINED INSTALL_EXAMPLESDIR)
    set(INSTALL_EXAMPLESDIR "examples")
endif()

#set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}")

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Network Svg Widgets X11Extras)
find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS DBus)
find_package(KF5WindowSystem COMPONENTS KF5WindowSystemConfig REQUIRED)

if(WITH_RISCV)
    list(APPEND CMAKE_PREFIX_PATH "~/.local/lib/python3.11/site-packages/torch")
else()
    list(APPEND CMAKE_PREFIX_PATH "~/.local/lib/python3.8/site-packages/torch")
endif()

find_package(Torch REQUIRED)

message(STATUS "    TORCH_CXX_FLAGS: ${TORCH_CXX_FLAGS}")
message(STATUS "    torch include: ${TORCH_INCLUDE_DIRS}")
message(STATUS "    torch library: ${TORCH_LIBRARIES}")


if(WITH_RISCV)
    include(live/riscv/fast_tokenizer/FastTokenizer.cmake)
else()
    include(live/x86/fast_tokenizer/FastTokenizer.cmake)
endif()
include_directories(${FAST_TOKENIZER_INCS})
set(source_files
    src/cli/commandargument.cpp src/cli/commandargument.h
    src/cli/commandlineparser.cpp src/cli/commandlineparser.h
    src/cli/commandoption.cpp src/cli/commandoption.h
    src/common/CommandLineOptions.cpp src/common/CommandLineOptions.h
    src/common/Enum.h
    src/common/Global.h
    src/common/Logger.cpp src/common/Logger.h
    src/common/my_av.h
    src/common/my_qt.h
    src/common/my_x.h
    src/config/buttonlistview.cpp src/config/buttonlistview.h
    src/config/clickablelabel.cpp src/config/clickablelabel.h
    src/config/configwindow.cpp src/config/configwindow.h
    src/config/extendedslider.cpp src/config/extendedslider.h
    src/config/filenameeditor.cpp src/config/filenameeditor.h
    src/config/geneneralconf.cpp src/config/geneneralconf.h
    src/config/strftimechooserwidget.cpp src/config/strftimechooserwidget.h
    src/config/uicoloreditor.cpp src/config/uicoloreditor.h
    src/config/visualseditor.cpp src/config/visualseditor.h
    src/core/capturerequest.cpp src/core/capturerequest.h
    src/core/controller.cpp src/core/controller.h
    src/core/kabuttonproxystyle.cpp src/core/kabuttonproxystyle.h
    src/core/kagroupbutton.cpp src/core/kagroupbutton.h
    src/main.cpp
    src/third-party/Qt-Color-Widgets/include/color_wheel.hpp
    src/third-party/Qt-Color-Widgets/src/color_utils.cpp src/third-party/Qt-Color-Widgets/src/color_utils.hpp
    src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
    src/third-party/singleapplication/singleapplication.cpp
    src/third-party/singleapplication/singleapplication.h
    src/third-party/singleapplication/singleapplication_p.h
    src/tools/AbstractActionToolWithWidget.cpp src/tools/AbstractActionToolWithWidget.h
    src/tools/abstractactiontool.cpp src/tools/abstractactiontool.h
    src/tools/abstractpathtool.cpp src/tools/abstractpathtool.h
    src/tools/abstracttwopointtool.cpp src/tools/abstracttwopointtool.h
    src/tools/arrow/arrowtool.cpp src/tools/arrow/arrowtool.h
    src/tools/blur/blurtool.cpp src/tools/blur/blurtool.h
    src/tools/capturecontext.cpp src/tools/capturecontext.h
    src/tools/capturetool.h
    src/tools/circle/circletool.cpp src/tools/circle/circletool.h
    src/tools/copy/copytool.cpp src/tools/copy/copytool.h
    src/tools/exit/exittool.cpp src/tools/exit/exittool.h
    src/tools/imgur/imguruploader.cpp src/tools/imgur/imguruploader.h
    src/tools/imgur/imguruploadertool.cpp src/tools/imgur/imguruploadertool.h
    src/tools/launcher/applaunchertool.cpp src/tools/launcher/applaunchertool.h
    src/tools/launcher/applauncherwidget.cpp src/tools/launcher/applauncherwidget.h
    src/tools/launcher/launcheritemdelegate.cpp src/tools/launcher/launcheritemdelegate.h
    src/tools/launcher/openwithprogram.cpp src/tools/launcher/openwithprogram.h
    src/tools/launcher/terminallauncher.cpp src/tools/launcher/terminallauncher.h
    src/tools/line/linetool.cpp src/tools/line/linetool.h
    src/tools/marker/markertool.cpp src/tools/marker/markertool.h
    src/tools/move/movetool.cpp src/tools/move/movetool.h
    src/tools/options/options.cpp src/tools/options/options.h
    src/tools/pencil/penciltool.cpp src/tools/pencil/penciltool.h
    src/tools/pin/pintool.cpp src/tools/pin/pintool.h
    src/tools/pin/pinwidget.cpp src/tools/pin/pinwidget.h
    src/tools/rectangle/rectangletool.cpp src/tools/rectangle/rectangletool.h
    src/tools/redo/redotool.cpp src/tools/redo/redotool.h
    src/tools/save/saveastool.cpp src/tools/save/saveastool.h
    src/tools/save/savetool.cpp src/tools/save/savetool.h
    src/tools/selection/selectiontool.cpp src/tools/selection/selectiontool.h
    src/tools/sizeindicator/sizeindicatortool.cpp src/tools/sizeindicator/sizeindicatortool.h
    src/tools/text/textconfig.cpp src/tools/text/textconfig.h
    src/tools/text/texttool.cpp src/tools/text/texttool.h
    src/tools/text/textwidget.cpp src/tools/text/textwidget.h
    src/tools/toolfactory.cpp src/tools/toolfactory.h
    src/tools/undo/undotool.cpp src/tools/undo/undotool.h
    src/utils/colorutils.cpp src/utils/colorutils.h
    src/utils/confighandler.cpp src/utils/confighandler.h
    src/utils/desktopfileparse.cpp src/utils/desktopfileparse.h
    src/utils/desktopinfo.cpp src/utils/desktopinfo.h
    src/utils/filenamehandler.cpp src/utils/filenamehandler.h
    src/utils/globalvalues.cpp src/utils/globalvalues.h
    src/utils/mysavedialog.cpp src/utils/mysavedialog.h
    src/utils/pathinfo.cpp src/utils/pathinfo.h
    src/utils/screengrabber.cpp src/utils/screengrabber.h
    src/utils/screenshotsaver.cpp src/utils/screenshotsaver.h
    src/utils/systemnotification.cpp src/utils/systemnotification.h
    src/widgets/aboutdialog.cpp src/widgets/aboutdialog.h
    src/widgets/capture/buttonhandler.cpp src/widgets/capture/buttonhandler.h
    src/widgets/capture/capturebutton.cpp src/widgets/capture/capturebutton.h
    src/widgets/capture/capturewidget.cpp src/widgets/capture/capturewidget.h
    src/widgets/capture/colorpicker.cpp src/widgets/capture/colorpicker.h
    src/widgets/capture/font_options.cpp src/widgets/capture/font_options.h
    src/widgets/capture/font_options2.cpp src/widgets/capture/font_options2.h
    src/widgets/capture/fontsize_color_chose.cpp src/widgets/capture/fontsize_color_chose.h
    src/widgets/capture/fontsize_color_chose2.cpp src/widgets/capture/fontsize_color_chose2.h
    src/widgets/capture/hovereventfilter.cpp src/widgets/capture/hovereventfilter.h
    src/widgets/capture/modificationcommand.cpp src/widgets/capture/modificationcommand.h
    src/widgets/capture/notifierbox.cpp src/widgets/capture/notifierbox.h
    src/widgets/capture/save_location.cpp src/widgets/capture/save_location.h
    src/widgets/capture/save_location2.cpp src/widgets/capture/save_location2.h
    src/widgets/capture/selectionwidget.cpp src/widgets/capture/selectionwidget.h
    src/widgets/capturelauncher.cpp src/widgets/capturelauncher.h
    src/widgets/delaywidget.cpp src/widgets/delaywidget.h
    src/widgets/imagelabel.cpp src/widgets/imagelabel.h
    src/widgets/infowidget.cpp src/widgets/infowidget.h
    src/widgets/loadspinner.cpp src/widgets/loadspinner.h
    src/widgets/notificationwidget.cpp src/widgets/notificationwidget.h
    src/widgets/panel/sidepanelwidget.cpp src/widgets/panel/sidepanelwidget.h
    src/widgets/panel/utilitypanel.cpp src/widgets/panel/utilitypanel.h
    src/widgets/screentype.cpp src/widgets/screentype.h
    src/widgets/shortcutwidget.cpp src/widgets/shortcutwidget.h
    src/widgets/xatomhelper.cpp src/widgets/xatomhelper.h
    )


# Resources:
set(color_widgets_resource_files
    "src/third-party/Qt-Color-Widgets/src/alphaback.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/arrow-bottom-left.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/blur.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/circle-outline.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/close.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/cloud-upload.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/colorize.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/config.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/content-copy.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/content-copy.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/content-save.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/cursor-move.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/cut.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/exit-to-app.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/graphics.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/line.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/luping_icon.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/marker.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/mouse-off.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/mouse.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/name_edition.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/open_with.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/pencil.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/pin_icon.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/audio_record_active.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/audio_record_noactive.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/cursor_record_active.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/cursor_record_noactive.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/follow_mouse_record_active.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/record/follow_mouse_record_noactive.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/redo-variant.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/size_indicator.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/square.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/text.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/black/undo-variant.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/control_point.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/control_point@2x.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/control_point@3x.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/arrow-bottom-left.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/blur.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/circle-outline.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/copy.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/down.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/format-text.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/line.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/marker.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/pencil.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/pin_icon.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/square.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/dark-theme/undo-variant.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/black_bold.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/black_delete.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/black_italic.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/black_underline.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/bold.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/delete.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/italic.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/font/underline.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/arrow-bottom-left.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/blur.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/circle-outline.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/close.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/colorize.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/config.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/content-copy.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/content-copy.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/content-save.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/cursor-move.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/down.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/down_1.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/down_2.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/down_3.png"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/exit-to-app.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/format-text.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/graphics.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/line.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/luping.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/marker.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/mouse-off.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/mouse.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/name_edition.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/open_with.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/pencil.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/pin_icon.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/square.svg"
    "src/third-party/Qt-Color-Widgets/src/img/material/white/undo-variant.svg"
    )
qt_add_resources(source_files src/third-party/Qt-Color-Widgets/src/color_widgets.qrc)
#qt_add_resources(live-image-text "color_widgets"
#    PREFIX
#        "/"
##    BASE
##        "src/third-party/Qt-Color-Widgets/src"
#    FILES
#        ${color_widgets_resource_files}
#)
set(graphics_resource_files
    "alphaback.png"
    "img/material/black/arrow-bottom-left.svg"
    "img/material/black/blur.svg"
    "img/material/black/circle-outline.svg"
    "img/material/black/close.svg"
    "img/material/black/cloud-upload.svg"
    "img/material/black/colorize.svg"
    "img/material/black/config.svg"
    "img/material/black/content-copy.png"
    "img/material/black/content-copy.svg"
    "img/material/black/content-save.svg"
    "img/material/black/cursor-move.svg"
    "img/material/black/cut.svg"
    "img/material/black/exit-to-app.svg"
    "img/material/black/graphics.svg"
    "img/material/black/line.svg"
    "img/material/black/luping_icon.svg"
    "img/material/black/marker.svg"
    "img/material/black/mouse-off.svg"
    "img/material/black/mouse.svg"
    "img/material/black/name_edition.svg"
    "img/material/black/open_with.svg"
    "img/material/black/pencil.svg"
    "img/material/black/pin_icon.svg"
    "img/material/black/record/audio_record_active.png"
    "img/material/black/record/audio_record_noactive.png"
    "img/material/black/record/cursor_record_active.png"
    "img/material/black/record/cursor_record_noactive.png"
    "img/material/black/record/follow_mouse_record_active.png"
    "img/material/black/record/follow_mouse_record_noactive.png"
    "img/material/black/redo-variant.svg"
    "img/material/black/size_indicator.svg"
    "img/material/black/square.svg"
    "img/material/black/text.svg"
    "img/material/black/undo-variant.svg"
    "img/material/control_point.png"
    "img/material/control_point@2x.png"
    "img/material/control_point@3x.png"
    "img/material/dark-theme/arrow-bottom-left.png"
    "img/material/dark-theme/blur.png"
    "img/material/dark-theme/circle-outline.png"
    "img/material/dark-theme/copy.png"
    "img/material/dark-theme/down.png"
    "img/material/dark-theme/format-text.png"
    "img/material/dark-theme/line.png"
    "img/material/dark-theme/marker.png"
    "img/material/dark-theme/pencil.png"
    "img/material/dark-theme/pin_icon.png"
    "img/material/dark-theme/square.png"
    "img/material/dark-theme/undo-variant.png"
    "img/material/font/black_bold.png"
    "img/material/font/black_delete.png"
    "img/material/font/black_italic.png"
    "img/material/font/black_underline.png"
    "img/material/font/bold.svg"
    "img/material/font/delete.svg"
    "img/material/font/italic.svg"
    "img/material/font/underline.svg"
    "img/material/white/arrow-bottom-left.svg"
    "img/material/white/blur.svg"
    "img/material/white/circle-outline.svg"
    "img/material/white/close.svg"
    "img/material/white/colorize.svg"
    "img/material/white/config.svg"
    "img/material/white/content-copy.png"
    "img/material/white/content-copy.svg"
    "img/material/white/content-save.svg"
    "img/material/white/cursor-move.svg"
    "img/material/white/down.svg"
    "img/material/white/down_1.png"
    "img/material/white/down_2.png"
    "img/material/white/down_3.png"
    "img/material/white/exit-to-app.svg"
    "img/material/white/format-text.svg"
    "img/material/white/graphics.svg"
    "img/material/white/line.svg"
    "img/material/white/luping.svg"
    "img/material/white/marker.svg"
    "img/material/white/mouse-off.svg"
    "img/material/white/mouse.svg"
    "img/material/white/name_edition.svg"
    "img/material/white/open_with.svg"
    "img/material/white/pencil.svg"
    "img/material/white/pin_icon.svg"
    "img/material/white/square.svg"
    "img/material/white/undo-variant.svg"
    )
qt_add_resources(source_files
    graphics.qrc
    )
#qt_add_resources(live-image-text "graphics"
#    PREFIX
#        "/"
#    FILES
#        ${graphics_resource_files}
#)
add_executable(live-image-text ${source_files} ${live_files})

target_include_directories(live-image-text PUBLIC
    src/common
    src/third-party/Qt-Color-Widgets/include
    src/third-party/Qt-Color-Widgets/src
    src/third-party/singleapplication
    src/utils
    )
pkg_check_modules(GSettings REQUIRED
    gsettings-qt
    )
target_include_directories(live-image-text PRIVATE ${GSettings_INCLUDE_DIRS})
target_link_libraries(live-image-text PRIVATE ${GSettings_LIBRARIES})

pkg_check_modules(KYSDK_QTWIDGETS kysdk-qtwidgets)
target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDK_QTWIDGETS_LIBRARIES})

#pkg_check_modules(KYSDKKABASE_PKG kysdk-kabase)
#target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_INCLUDE_DIRS})
#target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_LIBRARY_DIRS})
#target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_LIBRARIES})

pkg_check_modules(KYSDK_WAYLANDHELPER kysdk-waylandhelper)
target_include_directories(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${KYSDK_WAYLANDHELPER_LIBRARIES})



target_include_directories(live-image-text PUBLIC
    /usr/include/KF5/KWindowSystem
    #    /usr/include/kysdk/applications
    #    /usr/include/x86_64-linux-gnu/qt5/QGSettings
    )
target_compile_definitions(live-image-text PUBLIC
    #    IMGUR_CLIENT_ID="\"313baf0c7b4d3ff\""
    #    APP_VERSION="\"1.0\""
    QAPPLICATION_CLASS=QApplication
    QT_DEPRECATED_WARNINGS
    SUPPORT_NEWUI
    SUPPORT_UKUI
    _FORTIFY_SOURCE=2

    )
#add_definitions(-DIMGUR_CLIENT_ID="313baf0c7b4d3ff")
#add_definitions(-DAPP_VERSION="1.0")

target_link_libraries(live-image-text PUBLIC
    KF5::WindowSystem
    Qt::Core
    Qt::Gui
    Qt::Network
    Qt::Svg
    Qt::Widgets
    Qt::X11Extras
    X11
    Xext
    Xfixes
    Xinerama
    Xtst
    avcodec
    avformat
    avutil
    pulse
    swscale
    ukui-log4qt
    )

target_compile_options(live-image-text PUBLIC
    -O2
    -std=c++0x
    )


if(WIN32)
    target_sources(live-image-text PUBLIC
        src/core/globalshortcutfilter.cpp src/core/globalshortcutfilter.h
        )

    target_link_libraries(live-image-text PUBLIC
        shell32
        user32
        )
endif()

if(UNIX AND NOT MACOS)
    target_sources(live-image-text PUBLIC
        src/core/flameshotdbusadapter.cpp src/core/flameshotdbusadapter.h
        src/utils/dbusutils.cpp src/utils/dbusutils.h
        )

    #    target_compile_definitions(live-image-text PUBLIC
    #        APP_PREFIX=\\\"\\\"
    #    )

    target_link_libraries(live-image-text PUBLIC
        Qt::DBus
        )
endif()

if(MSVC AND WIN32)
    target_link_libraries(live-image-text PUBLIC
        Advapi32.lib
        )
endif()

if(GCC AND WIN32)
    target_link_libraries(live-image-text PUBLIC
        Advapi32
        )
endif()

##live
#if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
#    qt_add_executable(live-image-text
#        MANUAL_FINALIZATION
#        ${PROJECT_SOURCES}
#        )
#    # Define target properties for Android with Qt 6 as:
#    #    set_property(TARGET live-image-text APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#    #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
#    # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
#else()
#    if(ANDROID)
#        add_library(live-image-text SHARED
#            ${PROJECT_SOURCES}
#            )
#        # Define properties for Android with Qt 5 after find_package() calls as:
#        #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    else()
#        add_executable(live-image-text
#            ${PROJECT_SOURCES}
#            )
#    endif()
#endif()
message("start library")
message(${DEPS})
message("end library")
target_link_libraries(live-image-text PRIVATE ${DEPS})
target_link_libraries(live-image-text PRIVATE "${OpenCV_LIBS}")
if(WITH_RISCV)
    target_link_libraries(live-image-text PRIVATE atomic)
endif()
target_link_libraries(live-image-text PRIVATE ${FAST_TOKENIZER_LIBS})
message(STATUS "    fast_tokenizer library: ${FAST_TOKENIZER_LIBS}")
target_link_libraries(live-image-text PRIVATE ${TORCH_LIBRARIES})
set_property(TARGET live-image-text PROPERTY CXX_STANDARD 17)
#target_link_libraries(live-image-text PRIVATE protobuf)

set_target_properties(live-image-text PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
    )

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(live-image-text)
endif()

if(WITH_RISCV)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/fast_tokenizer/lib/libcore_tokenizers.so DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_videoio.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_videoio.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_video.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_video.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_stitching.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_stitching.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_photo.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_photo.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_objdetect.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_objdetect.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_ml.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_ml.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_imgproc.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_imgproc.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_imgcodecs.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_imgcodecs.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_highgui.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_highgui.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_gapi.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_gapi.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_flann.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_flann.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_features2d.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_features2d.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_dnn.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_dnn.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_core.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_core.so.4.9.0 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_calib3d.so.409 DESTINATION /usr/lib/)
    install(FILES ${CMAKE_SOURCE_DIR}/live/riscv/opencv4.9/lib64/libopencv_calib3d.so.4.9.0 DESTINATION /usr/lib/)
endif()


install(DIRECTORY ${CMAKE_SOURCE_DIR}/live/inference DESTINATION /usr/share/live-image-text/)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/live/res DESTINATION /usr/share/live-image-text/)
install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)

#if(WITH_RISCV)
#    install(DIRECTORY ${CMAKE_SOURCE_DIR}/live/res DESTINATION /usr/share/live-image-text/)
#else()
#    install(DIRECTORY ${CMAKE_SOURCE_DIR}/live/res DESTINATION /usr/share/live-image-text/)
#endif()

##end live

#install(TARGETS live-image-text
#    RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
#    BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
#    LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
#    )
